package com.project.lx.text.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.project.lx.text.R;
import com.project.lx.text.adapter.FragmentAdapter;
import com.project.lx.text.base.BaseFragment;
import com.project.lx.text.widget.MyViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Meteor
 * @description: 类描述
 * @version:
 * @date: 2017/3/9 0009 20:32
 * @company: jijiaxuan.com
 * @email: lx802315@163.com
 */
public class FragmentB extends BaseFragment {

    public MyViewPager mViewPager;
    public TabLayout mTabLayout;

    @Override
    protected View initLayout(LayoutInflater inflater, ViewGroup container, boolean b) {
        View rootView = inflater.inflate(R.layout.layout_frag_b, null);
        mViewPager = (MyViewPager) rootView.findViewById(R.id.viewpager_b);
        mTabLayout = (TabLayout) rootView.findViewById(R.id.tabs_b);
        initViewPager();
        return rootView;
    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    @Override
    protected void lazyLoad() {

    }

    private void initViewPager() {
        List<String> titles = new ArrayList<>();
        titles.add("B-1");
        titles.add("B-2");
        titles.add("B-3");
        titles.add("B-4");


        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        List<Fragment> fragments = new ArrayList<>();

        fragments.add(new FragmentG());
        fragments.add(new FragmentH());
        fragments.add(new FragmentI());
        fragments.add(new FragmentJ());

        FragmentAdapter mFragmentAdapteradapter =
                new FragmentAdapter(getActivity().getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        mViewPager.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        mTabLayout.setupWithViewPager(mViewPager);
        //给TabLayout设置适配器
        mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
    }
}
